$(function() {
    //页数
    let arr = []
    let pagenNum = null
    function render(pageId) {
        $.ajax({
            type: 'get',
            url: 'http://localhost:3000/api/getmoneyctrl?pageid='+pageId,
            dataType: 'json',
            success(res) {
                console.log(res);            
                                                                  
                
                $('.main1').html(template('tql',{list:res.result}))
            }
        })
    }
    render(1)
      
    //分页渲染
    function pageRedner(pageId) {
        $.ajax({
            type: 'get',
            url: 'http://localhost:3000/api/getmoneyctrl?pageid='+pageId,
            dataType: 'json',
            success(res) {
                pagenNum = Math.ceil(res.count /10)
                arr.length = pagenNum
                $('#box').html(template('tmp',{list:arr}))
            }


        })
    }
    pageRedner(1)


    //分页的点击渲染
    let clickNum = 1

    
    $('.right').click(function() {        
        if (clickNum >= pagenNum ) {            
            return false            
        } else {
            clickNum = clickNum + 1
        }
        render(clickNum)
        $('option').eq(clickNum-1).prop('selected',true)
    })

    $('.left').click(function() {        
        if (clickNum < 2 ) {            
            return false            
        } else {
            clickNum = clickNum - 1
        }
        render(clickNum)
        $('option').eq(clickNum-1).prop('selected',true)
    })


    $('#box').on('change',function() {
        clickNum = $(this)[0].selectedIndex + 1
        console.log(clickNum);
        render(clickNum)
    })


})